package com.shuanwang.nl2sql_demo.nl2Sql.controller;

import com.shuanwang.nl2sql_demo.nl2Sql.service.Nl2SqlService;
import com.shuanwang.nl2sql_demo.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/nl2sql")
public class Nl2SqlController {

    @Autowired
    private Nl2SqlService nl2SqlService;

    @PostMapping("/query")
    public R query(@RequestBody Map<String, String> request) throws Exception {
        String naturalLanguage = request.get("query");
        // 调用服务生成 SQL 并执行查询
        List<Map<String, Object>> result = nl2SqlService.processQuery(naturalLanguage);
        return R.data(result);
    }

    @GetMapping("/schema/json")
    public R schemaJson() {
        return R.data(nl2SqlService.schemaJson());
    }
}
